#include <iostream>
#include <stdio.h>

#include<string.h>
#include<ctype.h>

#include <math.h>
#include<time.h>

using namespace std;

#define maxn 100

char arr[maxn];
// Carbon   Hydrogen    Oxygen  Nitrogen
double weight[]= {12.01, 1.008, 16.00, 14.01};

double getWeight(char c)
{
    double ret = 0;
    switch (c)
    {
    case  'C':
        ret = weight[0];
        break;
    case 'H':
        ret = weight[1];
        break;
    case  'O':
        ret = weight[2];
        break;
    case  'N':
        ret = weight[3];
        break;
    default:
        0;
    }
    return ret;
}

int main()
{
    int i, j, k; // loop
    int temp, count=0; // temp, count
    int a,b, n; // cin

    // result
    double result=0;
    int r1, r2,r3;

    // ----------
    int t, len, number, isPreNum;
    char preAlpha, tempChar;
    double tempWeight;

//    memset(arr, 0, sizeof(arr));
    cin >> t;
    while (t-- > 0)
    {
        scanf("%s", arr);
        // init
        len = strlen(arr);
        count=0;
        result = 0;
        preAlpha= '0';
        number = 1;
        isPreNum = 0;
        tempWeight = 0;

        for (i = 0; i < len ; i++)
        {
            tempChar =arr[i];

            if (isalpha(tempChar))
            {
                result += tempWeight;

                isPreNum = 0;
                tempWeight = 0;

                tempWeight = getWeight(tempChar);
                preAlpha =tempChar;
            }
            else
            {
                if (isPreNum == 0)
                {
                    tempWeight = (tempChar - '0') * getWeight(preAlpha);
                }
                else
                {
                    tempWeight = 10 * tempWeight + (tempChar - '0') * getWeight(preAlpha);
                }

                isPreNum = 1;
            }
        }
        
        result += tempWeight;

        // output
//        cout << result<<endl;
        printf("%.3f\n", result);
    }


    return 0;
}